<template>
    <a-alert class="error mb16" v-if="errors.length" type="error" showIcon :message="`保存基本信息时发生错误：`">
        <template #description>
            <ul>
                <li v-for="(v, k) in errors" :key="k">{{ v }}</li>
            </ul>
        </template>
    </a-alert>
    <a-alert class="mb16" v-else type="info" showIcon message="填写提示">
        <template #description>
            <ol>
                <li><b>必填内容</b>：项目名称、所属学科、项目来源、课题来源、负责学院、所属学院、项目开始时间、项目结束时间、在实验/实践中完成（实验室类型、实验室名称、拟进行实践的地点）</li>
                <li v-if="graduateTimeMsg.isJwc">项目结束时间必须晚于项目开始时间</li>
                <li v-else>项目结束时间必须在<b>项目开始时间的两年以后</b>，且在<b>负责人毕业以前</b></li>
            </ol>
        </template>
    </a-alert>
    <div class="mb16 basic-info-editor">
        <table>
            <colgroup>
                <col style="width: 160px;">
                <col style="width: 200px;">
                <col style="width: 160px;">
                <col style="width: 200px;">
            </colgroup>
            <!-- 项目基本信息 开始 -->
            <tr>
                <td>项目名称</td>
                <td colspan="3">
                    <a-input :bordered="false" :maxlength="150" show-count v-model:value="basicInfo.projectName" placeholder="请输入 项目名称" />
                </td>
            </tr>
            <tr>
                <td>所属学科</td>
                <td colspan="3">
                    <dict-select :bordered="false" dict="所属学科" prefix="" v-model:value="basicInfo.speciality" width="735px" />
                </td>
            </tr>
            <tr>
                <td>项目来源</td>
                <td colspan="3">
                    <dict-select :bordered="false" dict="项目来源" prefix="" v-model:value="basicInfo.projectSource" width="735px"/>
                </td>
            </tr>
            <tr>
                <td>课题来源</td>
                <td colspan="3">
                    <dict-select :bordered="false" dict="课题来源" prefix="" v-model:value="basicInfo.problemSource" width="735px"/>
                </td>
            </tr>
            <tr>
                <td>负责学院</td>
                <td>
                    <depart-select :bordered="false" prefix="" schema="学院" v-model:value="basicInfo.departId" disableEmpty width="280px" />
                </td>
                <td>所属学院</td>
                <td>
                    <depart-select :bordered="false" prefix="" schema="学院" v-model:value="basicInfo.belongDepartId" disableEmpty width="280px" />
                </td>
            </tr>
            <tr>
                <td>项目开始时间</td>
                <td>
                    <date-picker :bordered="false" format="YYYY-M-D" v-model:value="basicInfo.applyStartDate" />
                </td>
                <td>项目结束时间</td>
                <td>
                    <date-picker :bordered="false" format="YYYY-M-D" :disabled-date="disabledEndDate" v-model:value="basicInfo.applyEndDate" />
                </td>
            </tr>
            <tr>
                <td>企业导师</td>
                <td>
                    <a-input :bordered="false" :maxlength="100" show-count v-model:value="basicInfo.corpTeacher" placeholder="请输入 企业导师" />
                </td>
                <td>企业导师联系电话</td>
                <td>
                    <a-input :bordered="false" :maxlength="100" show-count v-model:value="basicInfo.corpTeacherMobile" placeholder="请输入 企业导师联系电话" />
                </td>
            </tr>
            <tr>
                <td>在实验、实践中完成</td>
                <td colspan="3">
                    <dict-select :bordered="false" dict="是否在实验、实践中完成" prefix="" v-model:value="basicInfo.completeMethod" width="735px"/>
                </td>
            </tr>
            <tr v-if="basicInfo.completeMethod === '实验'">
                <td>实验室类型</td>
                <td>
                    <dict-select :bordered="false" dict="实验室类别" prefix="" v-model:value="basicInfo.labType" width="100%"/>
                </td>
                <td>实验室名称</td>
                <td>
                    <a-input :bordered="false" :maxlength="150" show-count v-model:value="basicInfo.labName" />
                </td>
            </tr>
            <tr v-if="basicInfo.completeMethod === '实践'">
                <td>拟进行实践的地点</td>
                <td colspan="3">
                    <a-input :bordered="false" :maxlength="150" show-count v-model:value="basicInfo.praticeLocation" placeholder="精确到市或单位" />
                </td>
            </tr>
            <tr>
                <td>主持人曾经参与科研的情况</td>
                <td colspan="3">
                    <a-textarea :bordered="false" :auto-size="{ minRows: 3 }" :maxlength="600" show-count v-model:value="basicInfo.managerSciResearch" />
                </td>
            </tr>
            <tr>
                <td>指导教师承担科研课题情况</td>
                <td colspan="3">
                    <a-textarea :bordered="false" :auto-size="{ minRows: 3 }" :maxlength="600" show-count v-model:value="basicInfo.guideTeacherSciResearch" />
                </td>
            </tr>
            <tr>
                <td>企业导师担任的职务及科研情况</td>
                <td colspan="3">
                    <a-textarea :bordered="false" :auto-size="{ minRows: 3 }" :maxlength="600" show-count v-model:value="basicInfo.corpTeacherSciResearch" />
                </td>
            </tr>
            <tr>
                <td>指导教师、企业导师支持情况</td>
                <td colspan="3">
                    <a-textarea :bordered="false" :auto-size="{ minRows: 3 }" :maxlength="600" show-count v-model:value="basicInfo.corpTeacherSupport" />
                </td>
            </tr>
        </table>
    </div>
    <a-flex justify="space-between">
        <a-space>
            <a-button type="primary" @click="save" :loading><SaveOutlined />保存基本信息</a-button>
            <a-button @click="reset" :loading ><ReloadOutlined />还原所有修改</a-button>
        </a-space>
        <a-button type="primary" :loading>
            保存并前往下一页
            <ArrowRightOutlined />
        </a-button>
    </a-flex>
</template>

<script setup>
import {ref, inject } from 'vue'
import app from "@/app.ts";
import { axios } from '@/axios';
import { useBasicInfo } from '@/modules/projects/components/useBasicInfo';

const errors = ref([]);
const data = inject("data");
const loading = ref(false);
const {
    basicInfo,
    errorStrings,
    graduateTimeMsg,
    disabledEndDate,
    reset,
    validate
} = await useBasicInfo(data);

async function save () {
    let flag = await validate();
    errors.value=[...errorStrings.value];
    if(!flag){
        return;
    }
    let handler = app.modals.loading("正在提交数据");
    loading.value = true;
    let msg = await axios.post("/api/proj/common/SaveEntrT",{
        id: data.basicInfo.ID,
        ...basicInfo.value
    });
    app.modals.showResponse(msg);

    if(msg.success){
        data.setBasicInfo(msg.basicInfo, msg.extInfo);
    }else{
        errors.value = [msg.msg];
    }
    loading.value=false;
    handler();
}
</script>

<style lang="less">
@import "@/assets/less/paper/paper.less";
ol {
    list-style: decimal;
}
</style>